﻿/**
 * ...
 * @author sminutoli
 */
import com.dmotiko.general.*
import com.dmotiko.prune.*
import mx.utils.Delegate;
 
class MainContent  extends Section
{
	private var content:MovieClip;
	
	private function initClip():Void {
		content = createEmptyMovieClip( "content", 1 );
	}
	
	public function initListeners():Void {
		Site.getApp().getClips().getSol().addEventListener( BaseClipEvent.SHOW_END, Delegate.create( this, sol_show ) );
		Site.getApp().addEventListener( WebSite.SECTION_CHANGED, Delegate.create( this, section_changed) );
		section_changed( { section: Site.getApp().getSection() } );
	}
		
	private function section_changed(e):Void 
	{
		
		var b:Boolean = Stage.width <= 1100;
		var sPath:String;
		
		switch( e.section ) {
			case SiteSections.HOME:
			if( b ) sPath = "home_1024.swf";
			else sPath = "home.swf";
			break;
			
			case SiteSections.PRUNE:
			if( b ) sPath = "prune_1024.swf";
			else sPath = "prune.swf";
			
			/*
			case SiteSections.CONTACT:
			case SiteSections.CONTACT_ATEN:
			case SiteSections.CONTACT_FRAN:
			case SiteSections.CONTACT_RRHH:
			case SiteSections.CONTACT_IMG:
			if ( b ) sPath = "contact_1024.swf";
			else sPath = "contact.swf";
			break;
			*/
			
			case SiteSections.NEWSLETTER:
			if ( b ) sPath = "newsletter_1024.swf";
			else sPath = "newsletter.swf";
			break;
						
			case SiteSections.STORES:
			if ( b ) sPath = "stores_1024.swf";
			else sPath = "stores.swf";
			break;
			
			case SiteSections.CAMPAIGN:
			if ( b ) sPath = "campaign_1024.swf";
			else sPath = "campaign.swf";
			break;
			
			case SiteSections.NEWS:
			if ( b ) sPath = "news_1024.swf";
			else sPath = "news.swf";
			break;
			
			case SiteSections.FASHION:
			if ( b ) sPath = "fashion.swf";
			else sPath = "fashion.swf";
			break;
			
			case SiteSections.CONTACT:
			case SiteSections.CONTACT_ATEN:
			case SiteSections.CONTACT_FRAN:
			case SiteSections.CONTACT_RRHH:
			case SiteSections.CONTACT_IMG:
			case SiteSections.FAQ:
			case SiteSections.GIFT:
			case SiteSections.BELONG:
			if ( b ) sPath = "belong_1024.swf";
			else sPath = "belong.swf";
			break;
						
			default:
			//content = createEmptyMovieClip( "content", 1 );
			break;
		}
		
		setData( sPath, e.last );
	}
	
	public function getContent():MovieClip {
		return content;
	}
	
	public function setData(sData:String, lastSection:String):Void {
		
		if ( data == undefined ) {
			//si es la primera vez no tengo que mostrar al sol y cargo el contenido directamente;
			super.setData( sData );
			return;
		}
		if ( sData != getData() ) {
			//sino grabo el contenido sin el setData porque trapeo el set data con el sol_show
			data = sData;
			//le digo al sol que se muestre y chequeo si tiene que haber reflejo en base a la ultima seccion
			Site.getApp().getClips().getSol().show( lastSection == SiteSections.STORES || lastSection == SiteSections.FASHION );
		} else {
			Site.getApp().getClips().getSol().dispatchEvent( { type: BaseClipEvent.SHOW_END } );
		}
	}
	
	private function sol_show():Void 
	{
		if ( Site.getApp().getSection() == SiteSections.HOME ) {
			if( content._url.indexOf("home") < 0 ) super.setData( data );
			return;
		}
		if ( Site.getApp().getSection() == SiteSections.CAMPAIGN ) {
			if ( content._url.indexOf("campaign") < 0 ) {
				super.setData( data );
				Site.getApp().getClips().getSol().hide();
			}
			return;
		}
		
		Site.getApp().getClips().getSol().hide();
		super.setData( data );
	}
	
	private function refreshData():Void {
		content.loadMovie( data.toString() );
	}
	
}